package homework2;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;


public class Test {
    public static void main(String[] args) throws ParseException {
        String info = "熊大,20,男,上海,2003-03-10;熊二,19,男,北京,2004-03-10;翠花,20,女,上海,2003-01-10";
        String[] splits = info.split(";");
        String num1 = splits[0];//熊大,20,男,上海,2003-03-10;
        String num2 = splits[1];//熊二,19,男,北京,2004-03-10;
        String num3 = splits[2];//翠花,20,女,上海,2003-01-10";
        String[] split1 = num1.split(",");//[熊大,20,男,上海,2003-03-10]
        String[] split2 = num2.split(",");//[熊二,19,男,北京,2004-03-10]
        String[] split3 = num3.split(",");//[翠花,20,女,上海,2003-01-10]
        int age1 = Integer.parseInt(split1[1]);//20
        int age2 = Integer.parseInt(split2[1]);//19
        int age3 = Integer.parseInt(split3[1]);//20
        char gender1 = split1[2].charAt(0);
        char gender2 = split2[2].charAt(0);
        char gender3 = split3[2].charAt(0);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate localDate1 = LocalDate.parse(split1[4], formatter);
        LocalDate localDate2 = LocalDate.parse(split2[4], formatter);
        LocalDate localDate3 = LocalDate.parse(split1[4], formatter);
        User user1 = new User(split1[0], age1, gender1, split1[3], localDate1, LocalDateTime.now());
        User user2 = new User(split2[0], age2, gender2, split1[3], localDate2, LocalDateTime.now());
        User user3 = new User(split2[0], age3, gender3, split1[3], localDate3, LocalDateTime.now());
        //功能1：向集合中存储多个User对象
        ArrayList<User> users = new ArrayList<>();
        users.add(user1);
        users.add(user2);
        users.add(user3);
        //功能2：打印输出2000年1月1日后出生的User对象信息
        String time = "2000-01-01";
        LocalDate localDate4 = LocalDate.parse(time);
        for (int i = 0; i < users.size(); i++) {
            User user = users.get(i);
            if (user.getBirthDate().isAfter(localDate4)){
                System.out.println(user);
            }
        }


    }
}
